import type { CartItem } from '@/types/cart'
import { http } from '@/utils/http'

/**
 * 获取购物车数据
 * @returns 购物车列表
 */
export const getAllCart = () => {
  return http<CartItem[]>({
    url: '/member/cart',
    method: 'GET',
  })
}

/**
 * 加入购物车
 * @param data skuId:商品ID,count:数量
 * @returns
 */
export const addMemberCart = (data: { skuId: string; count: number }) => {
  return http({
    method: 'POST',
    url: '/member/cart',
    data,
  })
}

/**
 * 清除购物车
 * @param data SKUID集合
 * @returns
 */
export const deleteMemberCart = (data: { ids: string[] }) => {
  return http({
    url: '/member/cart',
    method: 'DELETE',
    data,
  })
}

/**
 * 修改购物车商品
 * @param skuId 商品skuID
 * @param data 修改内容
 * @returns
 */
export const putMemberCart = (skuId: string, data: { seleced?: boolean; count?: number }) => {
  return http({
    url: `/member/cart/${skuId}`,
    method: 'PUT',
    data,
  })
}

/**
 * 修改全选或反选
 * @param data
 * @returns
 */
export const putMemberCartSelectAll = (data: { selected: boolean }) => {
  return http({
    url: '/member/cart/selected',
    method: 'PUT',
    data,
  })
}
